package com.ruoyi.business.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.RecruitJobs;
import com.ruoyi.business.service.IRecruitJobsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 招聘岗位Controller
 * 
 * @author asher
 * @date 2021-11-22
 */
@RestController
@RequestMapping("/business/jobs")
public class RecruitJobsController extends BaseController
{
    @Autowired
    private IRecruitJobsService recruitJobsService;

    /**
     * 查询招聘岗位列表
     */
    @PreAuthorize("@ss.hasPermi('business:jobs:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecruitJobs recruitJobs)
    {
        startPage();
        List<RecruitJobs> list = recruitJobsService.selectRecruitJobsList(recruitJobs);
        return getDataTable(list);
    }

    /**
     * 导出招聘岗位列表
     */
    @PreAuthorize("@ss.hasPermi('business:jobs:export')")
    @Log(title = "招聘岗位", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RecruitJobs recruitJobs)
    {
        List<RecruitJobs> list = recruitJobsService.selectRecruitJobsList(recruitJobs);
        ExcelUtil<RecruitJobs> util = new ExcelUtil<RecruitJobs>(RecruitJobs.class);
        return util.exportExcel(list, "招聘岗位数据");
    }

    /**
     * 获取招聘岗位详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:jobs:query')")
    @GetMapping(value = "/{jobId}")
    public AjaxResult getInfo(@PathVariable("jobId") Long jobId)
    {
        return AjaxResult.success(recruitJobsService.selectRecruitJobsByJobId(jobId));
    }

    /**
     * 新增招聘岗位
     */
    @PreAuthorize("@ss.hasPermi('business:jobs:add')")
    @Log(title = "招聘岗位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecruitJobs recruitJobs)
    {
        return toAjax(recruitJobsService.insertRecruitJobs(recruitJobs));
    }

    /**
     * 修改招聘岗位
     */
    @PreAuthorize("@ss.hasPermi('business:jobs:edit')")
    @Log(title = "招聘岗位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecruitJobs recruitJobs)
    {
        return toAjax(recruitJobsService.updateRecruitJobs(recruitJobs));
    }

    /**
     * 删除招聘岗位
     */
    @PreAuthorize("@ss.hasPermi('business:jobs:remove')")
    @Log(title = "招聘岗位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{jobIds}")
    public AjaxResult remove(@PathVariable Long[] jobIds)
    {
        return toAjax(recruitJobsService.deleteRecruitJobsByJobIds(jobIds));
    }
}
